<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019-06-28
  Time: 9:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="true" %>
<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
    <script>
        var cxk="<%=request.getContextPath()%>";
    </script>
</head>
<body>
<div id="root">

    <modal :mask-closable="false" title="修改信息" @on-ok="doUpdate" v-model="drugModal" width="650" @on-cancel="">
        <i-form :label-width="80">
            <row>
                <i-col span="6">
                    <form-item label="编号:">
                        <i-input type="text" v-model="drugs.drugsid"/>
                    </form-item>
                </i-col>
                <i-col span="6">
                    <form-item label="药品名称:">
                        <i-input type="text" v-model="drugs.drugsName"/>
                    </form-item>
                </i-col>
                <i-col span="6">
                    <form-item label="药品规格:">
                        <i-input type="text" v-model="addDrugs.Specifications"/>
                    </form-item>
                </i-col>
                <i-col span="6">
                    <form-item label="产地:">
                        <i-input  v-model="drugs.chandi"/>
                    </form-item>
                </i-col>
            </row>
            <row>
                <i-col span="6">
                    <form-item label="价格/元:">
                        <i-input type="text" v-model="drugs.price"/>
                    </form-item>
                </i-col>
                <i-col span="6">
                    <form-item label="价格/元:">
                        <i-input type="text" v-model="drugs.prices"/>
                    </form-item>
                </i-col>
                <i-col span="6">
                    <form-item label="数量:">
                        <i-input type="text" v-model="drugs.number"/>
                    </form-item>
                </i-col>
                <i-col span="6">
                    <form-item label="单位:">
                        <i-select v-model="drugs.companyid">
                            <i-option v-for="item in companyList" :value="item.id" :key="item.id">{{item.companyids}}</i-option>
                        </i-select>
                    </form-item>
                </i-col>
            </row>
            <row>
                <i-col span="12">
                    <form-item label="类型:">
                        <i-select v-model="drugs.categoryid">
                            <i-option v-for="item in categoryList" :value="item.id" :key="item.id">{{item.drugsName}}</i-option>
                        </i-select>
                    </form-item>
                </i-col>
                <i-col span="12">
                    <form-item label="生产日期:">
                        <date-picker v-model="drugs.manufacture" type="date" format="yyyy-MM-dd"/>
                    </form-item>
                </i-col>
                <i-col span="24">
                    <form-item label="功效:">
                        <i-input type="textarea" v-model="drugs.effect"/>
                    </form-item>
                </i-col>
            </row>
        </i-form>
    </modal>
    <modal :mask-closable="false" title="添加信息" @on-ok="doAdd" v-model="addModal" width="650" @on-cancel="clear">
        <i-form :label-width="80">
            <row>
                <i-col span="7">
                    <form-item label="编号:">
                        <i-input type="text" v-model="addDrugs.drugsid"/>
                    </form-item>
                </i-col>
                <i-col span="7">
                    <form-item label="药品名称:">
                        <i-input type="text" v-model="addDrugs.drugsName"/>
                    </form-item>
                </i-col>
                <i-col span="6">
                    <form-item label="药品规格:">
                        <i-input type="text" v-model="addDrugs.Specifications"/>
                    </form-item>
                </i-col>
            </row>
            <row>
                <i-col span="6">
                    <form-item label="单价/元:">
                        <i-input type="text" v-model="addDrugs.price"/>
                    </form-item>
                </i-col>
                <i-col span="6">
                    <form-item label="数量:">
                        <Input-Number type="text" v-model="addDrugs.number" disabled value="0"/>
                    </form-item>
                </i-col>
                <i-col span="6">
                    <form-item label="单位:">
                        <i-select v-model="addDrugs.companyid">
                            <i-option v-for="item in companyList" :value="item.id" :key="item.id">{{item.companyids}}</i-option>
                        </i-select>
                    </form-item>
                </i-col>
                <i-col span="6">
                    <form-item label="产地:">
                        <i-input  v-model="addDrugs.chandi"/>
                    </form-item>
                </i-col>
            </row>
            <row>
                <i-col span="7">
                    <form-item label="类型:">
                        <i-select v-model="addDrugs.categoryid">
                            <i-option v-for="item in categoryList" :value="item.id" :key="item.id">{{item.drugsName}}</i-option>
                        </i-select>
                    </form-item>
                </i-col>
                <i-col span="7">
                    <form-item label="供应商:">
                        <i-select v-model="addDrugs.supplierId">
                            <i-option v-for="item in supplierList" :value="item.id" :key="item.id">{{item.companyName}}</i-option>
                        </i-select>
                    </form-item>
                </i-col>
                <i-col span="7">
                    <form-item label="仓库位置:">
                        <i-select v-model="addDrugs.bitId">
                            <i-option v-for="item in warehouseList" :value="item.wid" :key="item.wid">{{item.wname}}</i-option>
                        </i-select>
                    </form-item>
                </i-col>
            </row>
            <row>
                <i-col span="12">
                    <form-item label="生产日期:">
                        <date-picker v-model="addDrugs.manufacture" type="date" format="yyyy-MM-dd"/>
                    </form-item>
                </i-col>
                <i-col span="12">
                    <form-item label="到期日期:">
                        <date-picker v-model="addDrugs.baozhiqi" type="date" format="yyyy-MM-dd"/>
                    </form-item>
                </i-col>
            </row>
            <row>
                <i-col span="24">
                    <form-item label="功效:">
                        <i-input type="textarea" v-model="addDrugs.effect"/>
                    </form-item>
                </i-col>
            </row>
        </i-form>
    </modal>


    <Row  style="margin-top: 10px;margin-bottom: -20px">
        <i-col>
            <i-form :label-width="80" :inline="true">
                <form-item label="编号">
                    <i-input v-model="id" type="number"></i-input>
                </form-item>
                <form-item label="药名">
                    <i-input v-model="name1" placeholder="名称"></i-input>
                </form-item>
                <form-item label="单位">
                    <i-select v-model="name2">
                        <i-option value="请选择">请选择</i-option>
                        <i-option v-for="item in companyList" :value="item.companyids" :key="item.id">{{item.companyids}}</i-option>
                    </i-select>
                </form-item>
                <form-item label="类别">
                    <i-select v-model="name3">
                        <i-option value="请选择">请选择</i-option>
                        <i-option v-for="item in categoryList" :value="item.drugsName" :key="item.id">{{item.drugsName}}</i-option>
                    </i-select>
                </form-item>
                <form-item label="供应商">
                    <i-select v-model="name4">
                        <i-option value="请选择">请选择</i-option>
                        <i-option v-for="item in supplierList" :value="item.companyName" :key="item.id">{{item.companyName}}</i-option>
                    </i-select>
                </form-item>
                <i-button type="primary" icon="ios-search" @click="select">查询</i-button>
                <i-button @click="fanhuishangyiji">返回上一级</i-button>
                <%--<i-button type="info" icon="ios-add" @click="openAdd">添加</i-button>--%>
                <%--<i-button  @click="huishouzhan">回收站</i-button>--%>
            </i-form>
        </i-col>
    </Row>



    <i-table :height="heights" style="margin-top:20px;margin-right: 50px;margin-left: 50px;" :data="datas" :columns="colunmsss" border>
        <template slot="caozuo" slot-scope="{row}">

            <i-button size="small"  @click="yichu(row)">移除</i-button>
            <%--<i-button size="small" type="primary" @click="openModal(row)">修改</i-button>--%>
            <%--<i-button size="small" type="error" @click="doDel(row)">删除</i-button>--%>
        </template>
        <template slot="supplier" slot-scope="{row}">
            <span></span>
        </template>
    </i-table>
    <page :total="totals"  @on-change="onchenge" :page-Size="pageSize" show-sizer :page-size-opts="[5,10,15,20]" @on-page-size-change="onPageSizeChange"></page>
</div>
<script>
    let _this = null;
    new Vue({
        el:"#root",
        data:{
            datas:[],
            showhidess:false,
            asdadasd:1,
            colunmsss:[
                {title:"编号", key:"drugsid", sortable:true},
                {title:"药品名称", key:"drugsName", tooltip:true},
                {title:"单价/元", key:"price"},
                {title:"售价/元", key:"prices"},
                // {title:"售价/元",key:"prices"},
                {title:"数量", key:"number"},
                {title:"单位", key:"companyids"},
                {title:"供应商",key:"companyName"},
                {title:"产地",key:"chandi"},
                {title:"类型", key:"drugsNametype"},
                {title:"功效", key:"effect", tooltip:true},
                {title:"生产日期", key:"manufacture"},
                // {title:"到期日期",key:"baozhiqi"},
                {title:"操作", slot:"caozuo"},

            ],
            heights:0,
            totals:0,
            pageNo:0,
            pageSize:5,
            id:"",
            name1:"",
            drugModal:false,
            companyList:[],
            categoryList:[],
            supplierList:[],
            drugs:{},
            addModal:false,
            addDrugs:{},
            warehouseList:[],
            name2:"",
            name3:"",
            name4:""
        },
        methods:{
            onchenge(size){
                this.pageNo = size;
                this.select();
            },
            onPageSizeChange(size){
                this.pageSize = size;
                this.select();
            },
            select(){
                // searchAll
                axios.get("/selecctsssssssssssssssssssss?id="+_this.id+"&name1="+_this.name1+"&pageNo="+_this.pageNo+"&pageSize="+_this.pageSize+"&name2="+this.name2+"&name3="+this.name3+"&name4="+this.name4).then(({data})=>{

                    // axios.get("/spxs/selecct?id="+_this.id+"&name1="+_this.name1+"&pageNo="+_this.pageNo+"&pageSize="+_this.pageSize).then(({data})=>{


                    _this.datas = data.obj.list;
                    _this.totals = data.obj.tatle;
                    _this.heights = data.obj.list.length * 48 + 40;
                })
            },
            selectType(){
                // axios.get("").then(({data})=>{
                //     _this.shuzu = data.obj;
                // })
            },
            openModal(row){
                this.drugs = {};
                Object.assign(this.drugs,row)
                this.drugModal=true
            },
            searchCompany(){
                // 单位：瓶，盒
                axios.get(`${cxk}/zdrug/company`)
                    .then(({data})=>{
                        this.companyList=data.obj;
                    })

                //药品类型
                axios.get(`${cxk}/yaopinleixing`)
                    .then(({data})=>{
                        this.categoryList=data.obj;
                    })

                //查全部药品
                <%--axios.get(`${cxk}/zdrug/searchAll`)--%>
                    <%--.then(({data})=>{--%>
                        <%--this.datas = data.obj;--%>
                    <%--})--%>

                //给供应商下拉框赋值
                axios.get(`${cxk}/supplier/searchAll`)
                    .then(({data})=>{
                        this.supplierList = data.obj;
                    })

                //给仓库下拉框赋值
                axios.get(`${cxk}/kucun/searchWare`)
                    .then(({data})=>{
                        this.warehouseList=data.obj;
                    })
            },
            clear(){
                // this.addDrugs = null;
            },
            doUpdate(){
                this.drugs.manufacture = moment(this.drugs.manufacture).format("YYYY-MM-DD")
                axios.post(`${cxk}/zdrug/update`,this.drugs)
                    .then(({data})=>{
                        iview.Message.warning(data.msg)
                        this.select();
                    })
            },
            openAdd(){
                this.addModal=true;
            },
            doAdd(){
                this.addDrugs.manufacture = moment(this.addDrugs.manufacture).format("YYYY-MM-DD")
                this.addDrugs.baozhiqi = moment(this.addDrugs.baozhiqi).format("YYYY-MM-DD")
                console.log(this.addDrugs.supplierId)
                axios.post(`${cxk}/zdrug/add`,this.addDrugs)
                    .then(({data})=>{
                        this.addDrugs = {};
                        this.select();
                        iview.Message.warning(data.msg)
                    })

            },
            doDel(row){
                this.$Modal.confirm({
                    title:"提示:",
                    content:"确定删除!",
                    onOk(){
                        axios.post(`${cxk}/zdrug/del?id=${row.id}`)
                            .then(({data})=>{
                                iview.Message.warning(data.msg)
                                _this.select();
                            })
                    }
                })
            },
            huishouzhan(){
                location.href='/huishoussssssss';
            },
            fanhuishangyiji(){
                location.href='/fanhuishangyiji';
            },
            yichu(row){
                axios.get("/yichu?id="+row.id).then(({data})=>{
                        iview.Message.warning(data.msg)
                        this.select();
                })
            }
        },
        mounted(){
            this.select();
            // this.selectType();
            this.searchCompany();
        },
        created(){
            _this = this;
        }
    })
</script>
</body>
</html>
